<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="theme-color" content="#375EAB">
<title>Gosl &ndash; package fdm</title>
<link type="text/css" rel="stylesheet" href="static/style.css">
<script type="text/javascript" src="static/godocs.js"></script>
<style type="text/css"></style>
</head>
<body>
<div id="page" class=\wide">
<div class="container">
<h1>Gosl &ndash; <b>fdm</b> &ndash; Simple finite differences method</h1>
use 'godoc cmd/github.com/cpmech/gosl/fdm' for documentation on the github.com/cpmech/gosl/fdm command 

<!--
	Copyright 2009 The Go Authors. All rights reserved.
	Use of this source code is governed by a BSD-style
	license that can be found in the LICENSE file.
-->
<!--
	Note: Static (i.e., not template-generated) href and id
	attributes start with "pkg-" to make it impossible for
	them to conflict with generated attributes (some of which
	correspond to Go identifiers).
-->

	<script type='text/javascript'>
	document.ANALYSIS_DATA = ;
	document.CALLGRAPH = ;
	</script>

	
		
		<div id="short-nav">
			<dl>
			<dd><code>import "github.com/cpmech/gosl/fdm"</code></dd>
			</dl>
			<dl>
			<dd><a href="#pkg-overview" class="overviewLink">Overview</a></dd>
			<dd><a href="#pkg-index" class="indexLink">Index</a></dd>
			
			
				<dd><a href="#pkg-subdirectories">Subdirectories</a></dd>
			
			</dl>
		</div>
		<!-- The package's Name is printed as title by the top-level template -->
		<div id="pkg-overview" class="toggleVisible">
			<div class="collapsed">
				<h2 class="toggleButton" title="Click to show Overview section">Overview ▹</h2>
			</div>
			<div class="expanded">
				<h2 class="toggleButton" title="Click to hide Overview section">Overview ▾</h2>
				
			</div>
		</div>
		

		<div id="pkg-index" class="toggleVisible">
		<div class="collapsed">
			<h2 class="toggleButton" title="Click to show Index section">Index ▹</h2>
		</div>
		<div class="expanded">
			<h2 class="toggleButton" title="Click to hide Index section">Index ▾</h2>

		<!-- Table of contents for API; must be named manual-nav to turn off auto nav. -->
			<div id="manual-nav">
			<dl>
			
			
			
				
				<dd><a href="#AssemblePoisson2d">func AssemblePoisson2d(K11, K12 *la.Triplet, F1 []float64, kx, ky float64, src Cb_src, g *Grid2d, e *Equations)</a></dd>
			
				
				<dd><a href="#InitK11andK12">func InitK11andK12(K11, K12 *la.Triplet, e *Equations)</a></dd>
			
				
				<dd><a href="#JoinVecs">func JoinVecs(U, U1, U2 []float64, e *Equations)</a></dd>
			
			
				
				<dd><a href="#Cb_fxy">type Cb_fxy</a></dd>
				
				
			
				
				<dd><a href="#Cb_src">type Cb_src</a></dd>
				
				
			
				
				<dd><a href="#Equations">type Equations</a></dd>
				
				
					
					<dd>&nbsp; &nbsp; <a href="#Equations.Init">func (e *Equations) Init(n int, peq_notsorted []int)</a></dd>
				
					
					<dd>&nbsp; &nbsp; <a href="#Equations.Print">func (e *Equations) Print()</a></dd>
				
			
				
				<dd><a href="#Grid2d">type Grid2d</a></dd>
				
				
					
					<dd>&nbsp; &nbsp; <a href="#Grid2d.Generate">func (o *Grid2d) Generate(fcn Cb_fxy, Fserial []float64) (X, Y, F [][]float64)</a></dd>
				
					
					<dd>&nbsp; &nbsp; <a href="#Grid2d.Init">func (o *Grid2d) Init(xmin, xmax, ymin, ymax float64, nx, ny int)</a></dd>
				
			
			
			</dl>
			</div><!-- #manual-nav -->

		

		
			<h4>Package files</h4>
			<p>
			<span style="font-size:90%">
			
				<a href="/src/github.com/cpmech/gosl/fdm/assembly.go">assembly.go</a>
			
				<a href="/src/github.com/cpmech/gosl/fdm/definitions.go">definitions.go</a>
			
				<a href="/src/github.com/cpmech/gosl/fdm/equations.go">equations.go</a>
			
				<a href="/src/github.com/cpmech/gosl/fdm/grid2d.go">grid2d.go</a>
			
			</span>
			</p>
		
		</div><!-- .expanded -->
		</div><!-- #pkg-index -->

		<div id="pkg-callgraph" class="toggle" style="display: none">
		<div class="collapsed">
			<h2 class="toggleButton" title="Click to show Internal Call Graph section">Internal call graph ▹</h2>
		</div> <!-- .expanded -->
		<div class="expanded">
			<h2 class="toggleButton" title="Click to hide Internal Call Graph section">Internal call graph ▾</h2>
			<p>
			  In the call graph viewer below, each node
			  is a function belonging to this package
			  and its children are the functions it
			  calls&mdash;perhaps dynamically.
			</p>
			<p>
			  The root nodes are the entry points of the
			  package: functions that may be called from
			  outside the package.
			  There may be non-exported or anonymous
			  functions among them if they are called
			  dynamically from another package.
			</p>
			<p>
			  Click a node to visit that function's source code.
			  From there you can visit its callers by
			  clicking its declaring <code>func</code>
			  token.
			</p>
			<p>
			  Functions may be omitted if they were
			  determined to be unreachable in the
			  particular programs or tests that were
			  analyzed.
			</p>
			<!-- Zero means show all package entry points. -->
			<ul style="margin-left: 0.5in" id="callgraph-0" class="treeview"></ul>
		</div>
		</div> <!-- #pkg-callgraph -->

		
		
		
			
			
			<h2 id="AssemblePoisson2d">func <a href="https://github.com/cpmech/gosl/blob/master/fdm/assembly.go?s=861:972#L19">AssemblePoisson2d</a></h2>
			<pre>func AssemblePoisson2d(K11, K12 *<a href="/pkg/github.com/cpmech/gosl/la/">la</a>.<a href="/pkg/github.com/cpmech/gosl/la/#Triplet">Triplet</a>, F1 []<a href="/pkg/builtin/#float64">float64</a>, kx, ky <a href="/pkg/builtin/#float64">float64</a>, src <a href="#Cb_src">Cb_src</a>, g *<a href="#Grid2d">Grid2d</a>, e *<a href="#Equations">Equations</a>)</pre>
			<p>
AssemblePoisson2d assembles K11 and K12 corresponding to the Poisson problem in 2D
</p>
<pre> Solving:
               ∂²u        ∂²u
          - kx ———  -  ky ———  =  s(x,y)
               ∂x²        ∂y²
Input:
  kx and ky -- the diffusion coefficients
  src -- the source term function s(x,y) (may be nil)
  g -- the 2D grid
  e -- the Equation numbers
Output:
  K11, K12 and F1 are assembled (must be pre-allocated)
</pre>

			
			

		
			
			
			<h2 id="InitK11andK12">func <a href="https://github.com/cpmech/gosl/blob/master/fdm/assembly.go?s=262:316#L2">InitK11andK12</a></h2>
			<pre>func InitK11andK12(K11, K12 *<a href="/pkg/github.com/cpmech/gosl/la/">la</a>.<a href="/pkg/github.com/cpmech/gosl/la/#Triplet">Triplet</a>, e *<a href="#Equations">Equations</a>)</pre>
			<p>
InitK11andK12 initialises the two triplets
</p>

			
			

		
			
			
			<h2 id="JoinVecs">func <a href="https://github.com/cpmech/gosl/blob/master/fdm/assembly.go?s=1828:1876#L57">JoinVecs</a></h2>
			<pre>func JoinVecs(U, U1, U2 []<a href="/pkg/builtin/#float64">float64</a>, e *<a href="#Equations">Equations</a>)</pre>
			<p>
JoinVecs joins U1 and U2 by placing their components at the right place in U
</p>

			
			

		
		
			
			
			<h2 id="Cb_fxy">type <a href="https://github.com/cpmech/gosl/blob/master/fdm/definitions.go?s=354:392#L1">Cb_fxy</a></h2>
			<pre>type Cb_fxy func(x, y <a href="/pkg/builtin/#float64">float64</a>) <a href="/pkg/builtin/#float64">float64</a></pre>
			<p>
Cb_fxy defnes the callback function type f(x,y)
</p>


			

			

			
			
			

			

			
		
			
			
			<h2 id="Cb_src">type <a href="https://github.com/cpmech/gosl/blob/master/fdm/definitions.go?s=242:301#L1">Cb_src</a></h2>
			<pre>type Cb_src func(x, y <a href="/pkg/builtin/#float64">float64</a>, args ...interface{}) <a href="/pkg/builtin/#float64">float64</a></pre>
			<p>
Cb_src defines the callback function type for the &#34;source&#34; term
</p>


			

			

			
			
			

			

			
		
			
			
			<h2 id="Equations">type <a href="https://github.com/cpmech/gosl/blob/master/fdm/equations.go?s=2670:2885#L52">Equations</a></h2>
			<pre>type Equations struct {
    N1, N2, N <a href="/pkg/builtin/#int">int</a>   <span class="comment">// unknowns, prescribed, total numbers</span>
    RF1, FR1  []<a href="/pkg/builtin/#int">int</a> <span class="comment">// reduced=&gt;full/full=&gt;reduced maps for unknowns</span>
    RF2, FR2  []<a href="/pkg/builtin/#int">int</a> <span class="comment">// reduced=&gt;full/full=&gt;reduced maps for prescribed</span>
}</pre>
			<p>
Equations holds the ids of known (prescribed) and unknown equations
</p>
<pre>K11 K12 =&gt; unknowns
K21 K22 =&gt; prescribed
 |   +---&gt; prescribed
 +-------&gt; unknowns

&#34;RF&#34; means &#34;reduced to full&#34;
&#34;FR&#34; means &#34;full to reduced&#34;
reduced 1: is a reduced system of equations where only unknown    equations are present
reduced 2: is a reduced system of equations where only prescribed equations are present
full     : corresponds to all equations, unknown and prescribed

Example:

N   = 9         =&gt; total number of equations
peq = [0  3  6] =&gt; prescribed equations

  0  1  2  3  4  5  6  7  8                       0   1  2   3   4  5   6   7  8
0 +--------+--------+------ 0 -- prescribed -- 0 [22] 21 21 [22] 21 21 [22] 21 21 0
1 |        |        |       1                  1  12  .. ..  12  .. ..  12  .. .. 1
2 |        |        |       2                  2  12  .. ..  12  .. ..  12  .. .. 2
3 +--------+--------+------ 3 -- prescribed -- 3 [22] 21 21 [22] 21 21 [22] 21 21 3
4 |        |        |       4                  4  12  .. ..  12  .. ..  12  .. .. 4
5 |        |        |       5                  5  12  .. ..  12  .. ..  12  .. .. 5
6 +--------+--------+------ 6 -- prescribed -- 6 [22] 21 21 [22] 21 21 [22] 21 21 6
7 |        |        |       7                  7  12  .. ..  12  .. ..  12  .. .. 7
8 |        |        |       8                  8  12  .. ..  12  .. ..  12  .. .. 8
  0  1  2  3  4  5  6  7  8                       0   1  2   3   4  5   6   7  8
  |        |        |
 pre      pre      pre                                 .. =&gt; 11 equations

N1 = 6 =&gt; number of equations of type 1 (unknowns)
N2 = 3 =&gt; number of equations of type 2 (prescribed)
N1 + N2 == N

       0  1  2  3  4  5
RF1 = [1  2  4  5  7  8]           =&gt; ex:  RF1[3] = full system equation # 5

       0  1  2  3  4  5  6  7  8
FR1 = [   0  1     2  3     4  5]  =&gt; ex:  FR1[5] = reduced system equation # 3
      -1       -1       -1         =&gt; indicates &#39;value not set&#39;

       0  1  2
RF2 = [0  3  6]                    =&gt; ex:  RF2[1] = full system equation # 3

       0  1  2  3  4  5  6  7  8
FR2 = [0        1        2      ]  =&gt; ex:  FR2[3] = reduced system equation # 1
         -1 -1    -1 -1    -1 -1   =&gt; indicates &#39;value not set&#39;
</pre>


			

			

			
			
			

			

			
				
				<h3 id="Equations.Init">func (*Equations) <a href="https://github.com/cpmech/gosl/blob/master/fdm/equations.go?s=2917:2969#L59">Init</a></h3>
				<pre>func (e *<a href="#Equations">Equations</a>) Init(n <a href="/pkg/builtin/#int">int</a>, peq_notsorted []<a href="/pkg/builtin/#int">int</a>)</pre>
				<p>
Init initialises Equations
</p>

				
				
				
			
				
				<h3 id="Equations.Print">func (*Equations) <a href="https://github.com/cpmech/gosl/blob/master/fdm/equations.go?s=3588:3615#L88">Print</a></h3>
				<pre>func (e *<a href="#Equations">Equations</a>) Print()</pre>
				<p>
Print prints information about Equations
</p>

				
				
				
			
		
			
			
			<h2 id="Grid2d">type <a href="https://github.com/cpmech/gosl/blob/master/fdm/grid2d.go?s=256:1056#L1">Grid2d</a></h2>
			<pre>type Grid2d struct {

    <span class="comment">// input</span>
    Xmin <a href="/pkg/builtin/#float64">float64</a> <span class="comment">// mininum x-coordinate</span>
    Xmax <a href="/pkg/builtin/#float64">float64</a> <span class="comment">// maximum x-coordinate</span>
    Ymin <a href="/pkg/builtin/#float64">float64</a> <span class="comment">// mininum y-coordinate</span>
    Ymax <a href="/pkg/builtin/#float64">float64</a> <span class="comment">// maximum y-coordinate</span>
    Nx   <a href="/pkg/builtin/#int">int</a>     <span class="comment">// number of divisions along x. Number of spacings = Nx - 1</span>
    Ny   <a href="/pkg/builtin/#int">int</a>     <span class="comment">// number of divisions along y. Number of spacings = Ny - 1</span>

    <span class="comment">// derived</span>
    N   <a href="/pkg/builtin/#int">int</a>     <span class="comment">// total number of points</span>
    Lx  <a href="/pkg/builtin/#float64">float64</a> <span class="comment">// length along x</span>
    Ly  <a href="/pkg/builtin/#float64">float64</a> <span class="comment">// length along y</span>
    Dx  <a href="/pkg/builtin/#float64">float64</a> <span class="comment">// increments along x</span>
    Dy  <a href="/pkg/builtin/#float64">float64</a> <span class="comment">// increments along y</span>
    Dxx <a href="/pkg/builtin/#float64">float64</a> <span class="comment">// squared x-increment</span>
    Dyy <a href="/pkg/builtin/#float64">float64</a> <span class="comment">// squared y-increment</span>

    <span class="comment">// derived: boundaries</span>
    L []<a href="/pkg/builtin/#int">int</a> <span class="comment">// indices of points along Left edge</span>
    R []<a href="/pkg/builtin/#int">int</a> <span class="comment">// indices of points along Right edge</span>
    B []<a href="/pkg/builtin/#int">int</a> <span class="comment">// indices of points along Bottom edge</span>
    T []<a href="/pkg/builtin/#int">int</a> <span class="comment">// indices of points along Top edge</span>
}</pre>
			<p>
Grid2d holds data representing a 2D grid
</p>


			

			

			
			
			

			

			
				
				<h3 id="Grid2d.Generate">func (*Grid2d) <a href="https://github.com/cpmech/gosl/blob/master/fdm/grid2d.go?s=1893:1971#L60">Generate</a></h3>
				<pre>func (o *<a href="#Grid2d">Grid2d</a>) Generate(fcn <a href="#Cb_fxy">Cb_fxy</a>, Fserial []<a href="/pkg/builtin/#float64">float64</a>) (X, Y, F [][]<a href="/pkg/builtin/#float64">float64</a>)</pre>
				<p>
Generate generates coordinates and may evaluate a function over the grid
</p>
<pre>Input:
  fcn -- function f(x,y) to compute F matrix (may be nil)
    or
  Fserial -- serialized f values F[i+j*Nx] (may be nil)
Output:
  X, Y, F(optional) -- matrices of coordinates and f(x,y) values
</pre>

				
				
				
			
				
				<h3 id="Grid2d.Init">func (*Grid2d) <a href="https://github.com/cpmech/gosl/blob/master/fdm/grid2d.go?s=1087:1152#L27">Init</a></h3>
				<pre>func (o *<a href="#Grid2d">Grid2d</a>) Init(xmin, xmax, ymin, ymax <a href="/pkg/builtin/#float64">float64</a>, nx, ny <a href="/pkg/builtin/#int">int</a>)</pre>
				<p>
Init initialises the grid
</p>

				
				
				
			
		
	

	





	
	
		<h2 id="pkg-subdirectories">Subdirectories</h2>
	
	


	<div class="pkg-dir">
		<table>
			<tr>
				<th class="pkg-name">Name</th>
				<th class="pkg-synopsis">Synopsis</th>
			</tr>

			
			<tr>
				<td colspan="2"><a href="..">..</a></td>
			</tr>
			

			
				
					<tr>
						<td class="pkg-name" style="padding-left: 0px;">
							<a href="figs/">figs</a>
						</td>
						<td class="pkg-synopsis">
							
						</td>
					</tr>
				
			
		</table>
	</div>


	


<div id="footer">
<br /><br />
<hr>
<pre class="copyright">
Copyright (c) 2016, The Gosl Authors. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

* Neither the name of Gosl nor the names of its
  contributors may be used to endorse or promote products derived from
  this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS AS IS
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

</pre><!-- copyright -->
</div><!-- footer -->

</div><!-- container -->
</div><!-- page -->
</body>
</html>
